package com.matt.domain.materials;

import com.matt.commons.model.Model;
import java.sql.Timestamp;
import javax.persistence.*;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Data
@Table(name = "user_materiels")
@EqualsAndHashCode(callSuper = true)
@NamedEntityGraph(
        name = "UserMateriels.withMateriels",
        attributeNodes = @NamedAttributeNode(value = "materiels", subgraph = "Materiels.withCateogry"),
        subgraphs = {
        @NamedSubgraph(name = "Materiels.withCateogry", attributeNodes = @NamedAttributeNode("category"))
        }
)
@Entity
public class UserMateriels extends Model {
  @Column(name = "aid", columnDefinition = " varchar(32) COMMENT '对应园区id' ")
  private String aid;

  /**
   * 用户
   */
  @Column(name = "uid", columnDefinition = " varchar(32) COMMENT 'staff id' ")
  private String uid;

  /**
   * 用户名称
   */
  @Column(name = "uname", nullable = false, columnDefinition = " varchar(50) COMMENT 'staffName' ")
  private String uname;

  /**
   * 物资
   */
//  @Column(name = "mid", columnDefinition = " varchar(32) COMMENT '物资id' ")
//  private String mid;

  @OneToOne(optional = false)
  @JoinColumn(name = "mid", columnDefinition = " varchar(32) COMMENT '物资id' ")
  private Materiels materiels;

  /**
   * 数量
   */
  @Column(name = "count", columnDefinition = " int COMMENT '持有数量' ")
  private Integer count;

  /**
   * 操作类型
   */
  @Column(name = "type", columnDefinition = " int default 0 COMMENT '关联来源， 0 借取，  1 领取' ")
  private Integer type = 0;

  /**
   * 创建时间
   */
  @Column(name = "created", nullable = false, columnDefinition = " datetime DEFAULT NOW() COMMENT '创建时间' ")
  private Timestamp created;


}